Test Setup Failed
Push — master ( 982d9a...a2862f )
by
unknown
03:40
created

BaseView.extend.initialize   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 9.4285
1
define(function(require) {
2
    'use strict';
3
4
    var ConfigureIntegrationView;
5
    var BaseView = require('oroui/js/app/views/base/view');
6
    var $ = require('jquery');
7
    var mediator = require('oroui/js/mediator');
8
    var widgetManager = require('oroui/js/widget-manager');
9
10
    ConfigureIntegrationView = BaseView.extend({
11
        optionNames: BaseView.prototype.optionNames.concat(['wid', 'dataFieldSelector', 'apiKeyFieldSelector']),
12
13
        /**
14
         * @inheritDoc
15
         */
16
        constructor: function ConfigureIntegrationView() {
17
            ConfigureIntegrationView.__super__.constructor.apply(this, arguments);
18
        },
19
20
        /**
21
         * @inheritDoc
22
         */
23
        initialize: function(options) {
24
            ConfigureIntegrationView.__super__.initialize.call(this, options);
25
26
            widgetManager.getWidgetInstance(this.wid, this.onWidgetLoad.bind(this));
27
        },
28
29
        onWidgetLoad: function(widget) {
30
            mediator.on('integrationFormReload:before', function(event) {
31
                event.reloadManually = false;
32
                widget.loadContent($.param(event.data), event.formEl.attr('method'));
33
            });
34
35
            widget.on('contentLoad', function() {
36
                var $dataField = this.$(this.dataFieldSelector);
37
                var $apiKeyField = this.$(this.apiKeyFieldSelector);
38
39
                if ($dataField.val() && !$apiKeyField.val()) {
40
                    var data = JSON.parse($dataField.val());
41
42
                    if (data.transport.apiKey) {
43
                        $apiKeyField.val(data.transport.apiKey);
44
                    }
45
                }
46
            }.bind(this));
47
        }
48
    });
49
50
    return ConfigureIntegrationView;
51
});
52
53